package com.xiaoshuidi.cloud.module.rooms.repository;

import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xiaoshuidi.cloud.module.rooms.mapper.RoomHouseInfoMapper;
import com.xiaoshuidi.cloud.module.rooms.pojo.RoomHouseInfo;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @author hans.zhang
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class RoomHouseInfoRepository extends ServiceImpl<RoomHouseInfoMapper, RoomHouseInfo> {
    public RoomHouseInfo getByRoomHouseId(@NonNull Long roomHouseId) {
        LambdaQueryWrapper<RoomHouseInfo> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(RoomHouseInfo::getRoomHouseId, roomHouseId);
        RoomHouseInfo roomHouseInfo = this.getOne(wrapper);
        if(ObjectUtil.isEmpty(roomHouseInfo)){
            roomHouseInfo = new RoomHouseInfo();
        }
        return roomHouseInfo;
    }
}
